package com.wangyadong.hobby.schedule.jobtask.mybatis.parse;

import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.Configuration;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2018/8/214:26
 **/
public class XmlParse {

    static final String path = "com/wangyadong/hobby/common/dao/sqlmap/WanwserMapper.xml";

    @Test
    public static void main(String[] args) throws IOException {
        Configuration configuration = new Configuration();
        try (InputStream inputStream = Resources.getResourceAsStream(path)) {
            XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, path, configuration.getSqlFragments());
            builder.parse();
        }
        MappedStatement mappedStatement = configuration.getMappedStatement("selectByPrimaryKey");

        Environment environment = configuration.getEnvironment();
        System.out.println(new File(path).toPath());
        System.out.println(new File("D:\\git\\hobby\\remote-wangyadong-hobby\\hobby\\src\\main\\java\\com\\wangyadong\\hobby\\dao\\sqlmap\\WanwserMapper.xml").lastModified());
        System.out.println(mappedStatement.getFetchSize());
        System.out.println(mappedStatement.getTimeout());
        System.out.println(mappedStatement.getStatementType());
        System.out.println(mappedStatement.getResultSetType());
        System.out.println(mappedStatement.isFlushCacheRequired());
        System.out.println(mappedStatement.isUseCache());
    }
}
